﻿using BeIT.MemCached;
using Helpers;
using System.Collections;
using System.Collections.Generic;

namespace Caching
{
    public class MemCache
    {

        private static MemcachedClient GetCache()
        {
            return MemcachedClient.GetInstance("Memcached");
        }


        public static void InsertCache(string key, object obj)
        {
            //if (obj == null)
            //{

            //    return;
            //}
            //if (obj.GetType().IsGenericType && (obj.GetType().GetGenericTypeDefinition() == typeof(List<>)))
            //{
            //    if (((IList)obj).Count == 0)
            //    {
            //        return;
            //    }
            //}
            //key = key.ToLower();
            //if (obj == null) return;
            //string json = JsonHelpers.Serialize(obj);
            //GetCache().Set(key, json);
        }

        public static T Get<T>(string key) where T : class
        {
            //key = key.ToLower();
            //var json = (string)GetCache().Get(key);
            //if (string.IsNullOrEmpty(json)) return null;
            ////try
            ////{
            //return JsonHelpers.Deserialize<T>(json);
            ////}
            ////catch (Exception)
            ////{

            ////    return null;
            ////}
            return null;
        }

        public static void RemoveCache(string key)
        {
            key = key.ToLower();
            GetCache().Set(key, "");
        }
        public static bool ClearCache()
        {
            return GetCache().FlushAll();
        }

    }
}
